package cn.xingzhen.jfield.componet;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

/**
 * @author wenqiang
 * @date 2023/5/5
 * @comment ..
 */
public class XzPanel extends JPanel {

    private final int defaultWidth = 10;
    private final int defaultHeight = 10;

    public XzPanel() {
        super();
        setPreferredSize(new Dimension(defaultWidth, defaultHeight));
        initDefault();
    }
    public XzPanel(int width) {
        super();
        setPreferredSize(new Dimension(width, defaultHeight));
        initDefault();
    }

    public XzPanel(int width, int height) {
        super();
        setPreferredSize(new Dimension(width, height));
        initDefault();
    }

    private void initDefault() {
        if(XzUIConfigure.SHOW_BORDER) {
            setBorder(BorderFactory.createLineBorder(XzUIConfigure.BORDER_COLOR));
        }
        setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    }

    public XzPanel add(Component component) {
        super.add(component);
        return this;
    }

    public XzPanel setPadding(int padding) {
        setBorder(new EmptyBorder(padding, padding, padding, padding));
        return this;
    }

    public XzPanel setPadding(int top, int left, int bottom, int right) {
        setBorder(new EmptyBorder(top, left, bottom, right));
        return this;
    }

}
